/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidades;

import controller.IngredientesJpaController;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Renato
 */
@Entity
@Table(name = "ingredientes")
@NamedQueries({@NamedQuery(name = "Ingredientes.findAll", query = "SELECT i FROM Ingredientes i"), @NamedQuery(name = "Ingredientes.findById", query = "SELECT i FROM Ingredientes i WHERE i.id = :id"), @NamedQuery(name = "Ingredientes.findByNome", query = "SELECT i FROM Ingredientes i WHERE i.nome = :nome"), @NamedQuery(name = "Ingredientes.findByQtde", query = "SELECT i FROM Ingredientes i WHERE i.qtde = :qtde"), @NamedQuery(name = "Ingredientes.findByUnidadeMedida", query = "SELECT i FROM Ingredientes i WHERE i.unidadeMedida = :unidadeMedida")})
public class Ingredientes implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "nome")
    private String nome;
    @Column(name = "qtde")
    private Integer qtde;
    @Basic(optional = false)
    @Column(name = "unidade_medida")
    private String unidadeMedida;
    @JoinTable(name = "composicao_prato", joinColumns = {@JoinColumn(name = "id_ingrediente", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "id_cardapio", referencedColumnName = "id")})
    @ManyToMany(fetch = FetchType.EAGER)
    private Set<Cardapio> cardapioCollection;

    public Ingredientes() {
        this.qtde = qtde;
        this.nome = nome;
        this.unidadeMedida = unidadeMedida;
    }

    public Ingredientes(Integer id) {
        this.id = id;
    }

    public Ingredientes(String nome, String unidadeMedida, Integer qtde) {
        this.qtde = qtde;
        this.nome = nome;
        this.unidadeMedida = unidadeMedida;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public Integer getQtde() {
        return qtde;
    }

    public void setQtde(Integer qtde) {
        this.qtde = qtde;
    }

    public String getUnidadeMedida() {
        return unidadeMedida;
    }

    public void setUnidadeMedida(String unidadeMedida) {
        this.unidadeMedida = unidadeMedida;
    }

    public Set<Cardapio> getCardapioCollection() {
        return cardapioCollection;
    }

    public void setCardapioCollection(Set<Cardapio> cardapioCollection) {
        this.cardapioCollection = cardapioCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Object)) {
            return false;
        }

        Ingredientes other = new Ingredientes();
        IngredientesJpaController aux = new IngredientesJpaController();
        other = aux.findIngredientes(id);
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
}